package com.accompany.fragment.order;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.accompany.R;
import com.accompany.adapter.OrderListAdapter;
import com.accompany.base.BaseFragment;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * 信息说明: 订单界面
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/3/14 15 ：50
 * 项目名称：yuanban
 */
public class OrderFragment extends BaseFragment implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener {
    @BindView(R.id.viewpager)
    ViewPager mViewPager;
    @BindView(R.id.rag_group)
    RadioGroup mRadgroup;
    private ArrayList<Fragment> mList = new ArrayList<>();
    @Override
    public int getLayoutResource(){
        return R.layout.fragment_order_view;
    }
    @Override
    public void initLayoutView(){
        initfragment();
        initView();
    }
    private void initView() {
        mViewPager.setCurrentItem(0);
        mRadgroup.check(R.id.rad_all);
        mRadgroup.setOnCheckedChangeListener(this);
        mViewPager.setOnPageChangeListener(this);
        mViewPager.setAdapter(new OrderListAdapter(getChildFragmentManager(), mList));
    }
    private void initfragment() {
        OrderAllFragment allFragment = new OrderAllFragment();
        mList.add(allFragment);
        ObligationOrderFragment obligation = new ObligationOrderFragment();
        mList.add(obligation);
        TobeServedFragment tobeServed = new TobeServedFragment();
        mList.add(tobeServed);
        CompleteFragment complete = new CompleteFragment();
        mList.add(complete);
    }
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rad_all:
                mViewPager.setCurrentItem(0, false);
                break;
            case R.id.rad_obl:
                mViewPager.setCurrentItem(1, false);
                break;
            case R.id.rad_service:
                mViewPager.setCurrentItem(2, false);
                break;
            case R.id.rad_comp:
                mViewPager.setCurrentItem(3, false);
                break;
            default:
                break;
        }
    }
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }
    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                mRadgroup.check(R.id.rad_all);
                break;
            case 1:
                mRadgroup.check(R.id.rad_obl);
                break;
            case 2:
                mRadgroup.check(R.id.rad_service);
                break;
            case 3:
                mRadgroup.check(R.id.rad_comp);
                break;
            default:
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
